package main

import (
	"com.go-micro.code/todolist/go-micro-todolist/api-gateway/pkg/logging"
	"com.go-micro.code/todolist/go-micro-todolist/api-gateway/services"
	"com.go-micro.code/todolist/go-micro-todolist/api-gateway/weblib"
	"com.go-micro.code/todolist/go-micro-todolist/api-gateway/wrappers"
	"go-micro.dev/v4"
	"go-micro.dev/v4/web"
)

func main() {
	//用户服务客户端
	usrSRV := micro.NewService(
		micro.Name("userService.client"),
		micro.WrapClient(wrappers.NewUserWrapper),
	)
	//用户服务实例调用
	usrService := services.NewUserService("userService", usrSRV.Client())

	//任务服务客户端
	tskSRV := micro.NewService(
		micro.Name("taskService.client"),
		micro.WrapClient(wrappers.NewTaskWrapper),
	)
	//任务服务实例调用
	taskService := services.NewTaskService("taskService", tskSRV.Client())

	//创建微服务api，暴露http接口
	server := web.NewService(
		web.Name("api-gateway"),
		web.Address(":4000"),
		web.Handler(weblib.NewRouter(usrService, taskService)),
		web.Metadata(map[string]string{"protocol": "http"}),
	)

	server.Init()
	if err := server.Run(); err != nil {
		logging.Error(err.Error())
	}

}
